package cn.itcast.order.service;

import cn.itcast.order.client.UserClient;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Resource
    private UserClient userClient ;

    public Order queryOrderById(Long orderId){
        Order order = orderMapper.findById(orderId) ;
        if(order == null){
            return order ;
        }
        User user = userClient.findById(order.getUserId()) ;
        order.setUser(user);
        return order ;
    }

    //@Autowired
    //private RestTemplate restTemplate;
    //
    //
    //public Order queryOrderById(Long orderId) {
    //    // 1.查询订单
    //    Order order = orderMapper.findById(orderId);
    //    if(order == null){
    //        return null ;
    //    }
    //    // 2。restTemplate做远程服务调用
    //    User user = restTemplate.getForObject( "http://userservice/user/" + order.getUserId(), User.class) ;
    //    order.setUser(user);
    //    // 3.返回
    //    return order;
    //}
}
